<?php 
class dmb{
	public function __construct(){
	}
	public function generate($db,$set){
		$tofile = $set[tofile];
		$tables = $set[tables];
		
		$text = "<?php\n";
		foreach($tables as $v){
			$var_name = null;
			if($v[var_name]){
				$var_name=$v[var_name];
			}else{
				$var_name=$v[table];
			}
			$where = $v[where];
			if(!$where){
				$where="1=1";
			}
			$rows = $db->query_pair_all("select $v[select] from $v[table] where $where");
			if(!$rows){
				continue;
			}
			$text.='$'.$var_name."=array(\n";
			$i=0;
			foreach ($rows as $k=>$v){
				if($i==0){
					$text.="\t'$k'=>'$v'";
				}else{
					$text.=",\n\t'$k'=>'$v'";
				}
				$i++;
			}
			$text.="\n);\n\n";
		}
		
		$text.="?>";
		
		$fh = fopen($tofile, "w");
		return fwrite($fh, $text);
	}
}
?>